var api = require('../../util/api.js');
Page({
    data: {
        
    },
    onLoad: function () {
        this.setData({
            page: api.page(10),
            userList: [],
            params : {
                roleKey: 'supervision'
            }
        });
        this.onReachBottom();
    },
    toMark: function (e) {
        var type = api.chain().khtype;
        api.chain({
            userId: e.currentTarget.dataset.userid,
            userName: e.currentTarget.dataset.userName
        });
        switch (type) {
            case 'wtsl':
                type = 'wtmx'
                break;
            case 'fdfs':
                type = 'gcfk'
                break;
            default:
                break;
        }
        wx.navigateTo({
            url: `/pages/ljjd/${type}/list`
        })

    },
    onReachBottom(e) {
        var _this = this;
        var page = _this.data.page;
        var params = _this.data.params;
        api.get(api.url.listUserByRoleKey,params,page).then(res => {
            page.setTotal(res.total);
            _this.setData({
                userList: _this.data.userList.concat(res.rows)
            });
            
        })
    },
    searchInputAction(e){
        let _this = this
        let value = e.detail.value
        if (value.length != 0) {
            _this.data.params['userName'] = value;
        }else{
            _this.data.params['userName'] = '';
        }
        _this.setData({
            userList : [],
            page: api.page(10)
        });
        _this.onReachBottom();
    }
});